package com.smartcampusbackend.controller;

import com.smartcampusbackend.model.Department;
import com.smartcampusbackend.model.Major;
import com.smartcampusbackend.service.DepartmentService;
import com.smartcampusbackend.service.MajorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api")
public class DepartmentController {
    
    private static final Logger logger = LoggerFactory.getLogger(DepartmentController.class);
    
    @Autowired
    private DepartmentService departmentService;
    
    @Autowired
    private MajorService majorService;
    
    /**
     * 获取所有院系
     * @return 院系列表
     */
    @GetMapping("/departments")
    public List<Department> getAllDepartments() {
        logger.info("获取所有院系");
        return departmentService.listAllDepartments();
    }
    
    /**
     * 根据ID获取院系
     * @param departmentId 院系ID
     * @return 院系信息
     */
    @GetMapping("/departments/{departmentId}")
    public Department getDepartmentById(@PathVariable Long departmentId) {
        logger.info("获取院系信息，departmentId: {}", departmentId);
        return departmentService.getDepartmentById(departmentId);
    }
    
    /**
     * 根据院系ID获取专业列表
     * @param departmentId 院系ID
     * @return 专业列表
     */
    @GetMapping("/departments/{departmentId}/majors")
    public List<Major> getMajorsByDepartment(@PathVariable Long departmentId) {
        logger.info("获取院系专业，departmentId: {}", departmentId);
        return majorService.listMajorsByDepartment(departmentId);
    }
} 